package org.jwcloud.project.module.zx.txzldp.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.jwcloud.project.module.zx.baseManager.service.repository.MatBaseManagerRepository;
import org.jwcloud.project.module.zx.common.FmtUtil;
import org.jwcloud.project.module.zx.common.Resp;
import org.jwcloud.project.module.zx.common.repository.RptCommonRepository;
import org.jwcloud.project.module.zx.common.service.RptUtService;
import org.jwcloud.project.module.zx.txzldp.service.repository.TxzldpCommonViewRepository;
import org.jwcloud.project.module.zx.txzldp.service.repository.TxzldpDoorRepository;
import org.jwcloud.project.module.zx.workTime.service.repository.MatWorkTimeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.jw.mid.mm.comm.common.controller.BaseController;
import com.jw.mid.mm.comm.common.controller.CrudController;
import com.jw.mid.mm.comm.common.json.Response;
import com.jw.mid.mm.comm.common.pagination.ListBounds;
import com.jw.mid.mm.comm.common.pagination.ListSlice;
import com.jw.mid.mm.comm.common.pagination.PageListSlice;
import com.jw.mid.mm.comm.common.pagination.Pagination;
import com.jw.mid.mm.comm.common.service.CrudService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "API - Controlle",
description = "项目维护", tags = "door")
@RestController
@Transactional
@RequestMapping("/rest/txzldp/door")
public class TxzldpDoorController extends BaseController{
	
	@Autowired
	public RptCommonRepository rptCommonRepository;
	
	@Autowired
	public TxzldpDoorRepository txzldpDoorRepository;
	
	@Autowired
    public RptUtService rptUtService;
	
	@RequestMapping("/txzldpDoor")
	public ModelAndView txzldpDoor(@RequestParam Map param, ModelAndView model) {
		model.setViewName("pages/door/TxzldpDoor.html");
		return model;
	}
	
	@RequestMapping("/txzldpDoorSub")
	public ModelAndView txzldpDoorSub(@RequestParam Map param, ModelAndView model) {
		model.addAllObjects(param);
		model.setViewName("pages/door/TxzldpDoorSub.html");
		return model;
	}
	
	@GetMapping("queryProjectTree")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp queryProjectTree(
    		@RequestParam(required = false) Map<String,String> param
    		){
		List temp = this.txzldpDoorRepository.queryDoorProject(param);
		List<Map<String, Object>> list = temp;
		List<Map<String, String>> listSub = this.txzldpDoorRepository.queryDoorProjectSub(param);
		for(Map<String, Object> obj: list) {
			List<Map<String, String>> innerList = new ArrayList();
			for(Map<String,String> subObj: listSub) {
				if(obj.get("id").equals(subObj.get("rel_project_door_id"))) {
					innerList.add(subObj);
				}
			}
			obj.put("inner", innerList);
		}
		WebMvcAutoConfigurationAdapter  a;
		return Resp.success(this.txzldpDoorRepository.queryDoorProject(param));
    }
	
	@GetMapping("queryDoorProject")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp queryDoorProject(
    		@RequestParam(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.queryDoorProject(param));
    }
	
	@GetMapping("queryDoorProjectSub")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp queryDoorProjectSub(
    		@RequestParam(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.queryDoorProjectSub(param));
    }
	
	@PostMapping("updateDoorProject")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp updateDoorProject(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.updateDoorProject(param));
    }
	
	@PostMapping("updateDoorProjectSub")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp updateDoorProjectSub(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.updateDoorProjectSub(param));
    }
	
	@PostMapping("insertDoorProject")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp insertDoorProject(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.insertDoorProject(param));
    }
	
	@PostMapping("insertDoorProjectSub")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp insertDoorProjectSub(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.insertDoorProjectSub(param));
    }
	
	@PostMapping("deleteDoorProject")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp deleteDoorProject(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.deleteDoorProject(param));
    }
	
	@PostMapping("deleteDoorProjectSub")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParams({
    })
    public Resp deleteDoorProjectSub(
    		@RequestBody(required = false) Map<String,String> param
    		){
		return Resp.success(this.txzldpDoorRepository.deleteDoorProjectSub(param));
    }
	
}